#include "widget.h"
#include "ui_widget.h"
#include <QShortcut>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->label->setText("");
    ui->horizontalSlider->setMinimum(0);
    ui->horizontalSlider->setMaximum(100);
    ui->horizontalSlider->setSingleStep(10);
    ui->horizontalSlider->setValue(0);


    //使用快捷键， 需要用到QShort类, " - " 进行减少， " = " 增加
    QShortcut* s1 = new QShortcut(this);
    s1->setKey(QKeySequence("-"));


    QShortcut* s2= new QShortcut(this);
    s2->setKey(QKeySequence("="));


    connect(s1, &QShortcut::activated, this, &Widget::subValue);
    connect(s2, &QShortcut::activated, this, &Widget::addValue);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_horizontalSlider_valueChanged(int value)
{
    ui->label->setText(QString::number(value));
}


void Widget::subValue()
{
    int value = ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(value - 20);
}
void Widget::addValue()
{
    int value = ui->horizontalSlider->value();
    ui->horizontalSlider->setValue(value + 20);
}
